package com.hspedu.generic;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

/**
 * @author 谷其昊
 * @version 1.0
 * @date 2022/2/11
 * @time 16:41
 */
public class GenericExercise {
    public static void main(String[] args) {
        HashSet<Student> students = new HashSet<>();
        students.add(new Student("jack",18));
        students.add(new Student("lucy",18));

        for (Student student : students) {
            System.out.println(student.getName() +" "+student.getAge());
        }

        HashMap<String, Student> stringStudentHashMap = new HashMap<>();
        stringStudentHashMap.put("bob",new Student("bob",18));
        stringStudentHashMap.put("mary",new Student("mary",18));
        Set<Map.Entry<String, Student>> entries = stringStudentHashMap.entrySet();
        for (Map.Entry<String, Student> entry : entries) {
            System.out.println(entry.getKey() +" " + entry.getValue());
        }
    }
}

class Student{
    private String name;
    private int age;

    public Student(String name , int age){
        this.name = name;
        this.age = age;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }
}
